package com.turing.data.scripts.contract.filter

import com.turing.common.util.Log

import com.turing.common.util.FileUtils
import com.turing.common.util.StringUtils
import com.turing.data.engine.CombineLongText
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

class InvestmentManager_30212_10_filter {

    static List< TaskElementVO.DrawResultVO > doConvert(DependParamsVO dependParams){

        String REGEX = /.*投资经理.*/
        String REGEX_NO = "投资顾问"

        def textPathMap = dependParams.textPathMap

        List<TaskElementVO.DrawResultVO > trueValueSet = new ArrayList<>()
        List<TaskElementVO.DrawResultVO > resultVOs = ScriptsUtils.tryInitResult(dependParams)
        def set = new HashSet()
        if (resultVOs!=null && resultVOs.size()>0) {
            for (int i = 0; i < resultVOs.size(); i++) {
                if(StringUtils.isEmpty(resultVOs.get(i).childTaskSn)){
//                    return  resultVOs
                    continue
                }
                def rawPath = textPathMap.get(resultVOs.get(i).childTaskSn)
                def rawText = FileUtils.loadJson(rawPath)
                String trueValue = CombineLongText.fetchNearbyText(resultVOs.get(i), rawText,20)

                if ( trueValue =~ REGEX && ! trueValue.contains(REGEX_NO) ){
//                    if(!set.contains(resultVOs[i].text)){
                        trueValueSet.add(resultVOs.get(i))
//                    }
//                    set.add(resultVOs[i].text)
                    return  trueValueSet
                }
            }
        }

        if(trueValueSet.size()==0){
            def defaultResultVO = new TaskElementVO.DrawResultVO()
            defaultResultVO.text = ""
            trueValueSet.add(defaultResultVO)
        }
//        Log.info("InvestmentManager_9792_10_filter_trueValueSet={}",trueValueSet)
        return  trueValueSet
    }

}
